<template>
  <div class="switch-list-control">
    <div class="item" v-for="item in options" :key="item.value">
      <div class="text">{{ item.label }}</div>
      <a-switch
        class="switch-box"
        size="small"
        :disabled="item.disabled"
        v-model:checked="val[item.value]"
      />
    </div>
  </div>
</template>

<script lang="ts">
import { defineComponent, computed } from 'vue';

export default defineComponent({
  name: 'SwitchListControl',
  props: {
    value: {
      type: Object,
      default: () => ({}),
    },
    controls: {
      type: Object,
      default: () => ({}),
    },
    controlKey: {
      type: String,
      default: () => '',
    },
    options: {
      type: Object,
      default: () => ({}),
    },
  },
  setup(props, context) {
    const val = computed({
      get: () => props.value,
      set: (val) =>
        context.emit('updateValue', val, props.controlKey, props.controls),
    });

    return {
      val,
    };
  },
});
</script>

<style lang="less" scoped>
.switch-list-control {
  .item {
    .flexRow(flex-start, center);
    margin-bottom: 8px;
    .text {
      margin-right: 8px;
    }
  }
}
</style>
